const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
var path = require('path')
var webpack = require('webpack')

// const utils = require("./src/components/vue-hiprint-example-master/build/utils");
// const {ExtractTextPlugin} = require("./src/components/vue-hiprint-example-master/build/vue-loader.conf");
const NODE_ENV = process.env.NODE_ENV

module.exports = {
  entry: NODE_ENV === 'development' ? './src/main.js' : './index.js',
  // entry: './src/main.js',
  output: {
    // path: path.resolve(__dirname, NODE_ENV=='development' ? "./dist":'./vip-try-3.x.x/html/magicalcoder/assets/drag/js/user/iframe/element/2.10.1/components/'),
    path: path.resolve(__dirname, NODE_ENV === 'development' ? "./dist" : './public'),
    publicPath: NODE_ENV === 'development' ? '/dist/' : '',
    filename: 'vue-magicalcoder-demo.js',
    library: 'vue-magicalcoder-demo', // 指定的就是你使用require时的模块名
    libraryTarget: 'umd',// 指定输出格式
    umdNamedDefine: true // 会对 UMD 的构建过程中的 AMD 模块进行命名。否则就使用匿名的 define
  },
  module: {
    rules: [
      {
        test: /fs$/,
        use: 'null-loader'
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "babel-loader"
      },
      {
        test: /\.ico$/,
        use: 'url-loader',
      },
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ],
      },
      {
        test: /\.scss$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'sass-loader'
        ],
      },
      {
        test: /\.sass$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'sass-loader?indentedSyntax'
        ],
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
            // Since sass-loader (weirdly) has SCSS as its default parse mode, we map
            // the "scss" and "sass" values for the lang attribute to the right configs here.
            // other preprocessors should work out of the box, no loader config like this necessary.
            'scss': [
              'vue-style-loader',
              'css-loader',
              'sass-loader'
            ],
            'sass': [
              'vue-style-loader',
              'css-loader',
              'sass-loader?indentedSyntax'
            ]
          }
          // other vue-loader options go here
        }
      },
      // {
      //   test: /\.js$/,
      //   exclude: /node_modules/,
      //   use: {
      //     loader: 'babel-loader',
      //     options: {
      //       presets: ['@babel/preset-env']
      //     }
      //   }
      // },
      // {
      //   test: /\.(png|jpg|gif)$/,
      //   loader:"url-loader",
      //   options:{
      //     name:"[name]_[hash].[ext]",
      //     limit:100 * 1024 // 只对小于100kb的图片做base64转化
      //   }
      // },
      {
        test: /\.(png|jpg|gif)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        },
      },
      {
        test: /\.(woff|woff2|ttf|eot|svg)/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
    },
    extensions: ['*', '.js', '.vue', '.json']
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true,
    proxy: {
      '/youyaboot-admin': {
        target: 'http://localhost:18080',
        changeOrigin: true,
      }
    },
  },
  performance: {
    hints: false
  },
  plugins: []
}

// let transformRemoveConsolePlugin = [];

if (process.env.NODE_ENV === 'production') {
  // http://vue-loader.vuejs.org/en/workflow/production.html
  // transformRemoveConsolePlugin = ['transform-remove-console']
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    // new webpack.optimize.UglifyJsPlugin({
    //   sourceMap: true,
    //   compress: {
    //     warnings: false
    //   }
    // }),
    new webpack.optimize.LimitChunkCountPlugin({
      maxChunks: 1, // Must be greater than or equal to one
      minChunkSize: 1000
    }),
    // new UglifyJsPlugin({
    //   uglifyOptions:{
    //     compress: {
    //       warnings: false
    //     }
    //   }
    // }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    }),


  ])
} else {
  module.exports.devtool = '#eval-source-map'
}



